{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="float-right">
        <button type="submit" form="form-payment" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fas fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn btn-light"><i class="fas fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ol class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
          <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ol>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
      <div class="alert alert-danger alert-dismissible"><i class="fas fa-exclamation-circle"></i> {{ error_warning }}
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </div>
    {% endif %}
    <div class="alert alert-info">
      <form action="{{ registration_url }}" method="post" enctype="multipart/form-data" target="_blank"  id="registration-form">
        <input type="hidden" name="locale" value="{{ locale }}"/>
        <input type="hidden" name="spId" value="{{ sp_id }}"/>
        <input type="hidden" name="uniqueId" value="{{ unique_id }}"/>
        <input type="hidden" name="allowedLoginDomains[]" value="{{ allowed_login_domain }}"/>
        {% for login_redirect_url in login_redirect_urls %}
          <input type="hidden" name="loginRedirectURLs[]" value="{{ login_redirect_url }}"/>
        {% endfor %}
        <input type="hidden" name="storeDescription" value="{{ store_name }}"/>
        <input type="hidden" name="language" value="{{ simple_path_language }}">
        <input type="hidden" name="sandboxMerchantIPNURL" value="{{ ipn_url }}">
        <input type="hidden" name="productionMerchantIPNURL" value="{{ ipn_url }}">
        <input type="hidden" name="returnMethod" value="POST">
        <button type="button" id="sign-up" class="btn btn-link">{{ text_amazon_signup }}</button>
        <button type="button" class="close" data-dismiss="alert">&times;</button>
      </form>
      <div id="container-credentials">
        <div class="col-sm-12 mb-3">
          <textarea name="credentials" id="input-credentials" placeholder="{{ text_credentials }}" rows="7" class="form-control"></textarea>
        </div>
        <div class="col-sm-5">
          <button id="button-credentials" class="btn btn-primary" type="button">{{ text_validate_credentials }}</button>
        </div>
      </div>
    </div>
    <div class="card">
      <div class="card-header"><i class="fas fa-pencil-alt"></i> {{ text_edit }}</div>
      <div class="card-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-payment" class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-payment-region">{{ entry_payment_region }}</label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_payment_region" id="amazon-login-pay-payment_region" class="form-control">
                {% for payment_region_code, payment_region_name in payment_regions %}
                  {% if payment_region_code == payment_amazon_login_pay_payment_region %}
                    <option value="{{ payment_region_code }}" selected="selected">{{ payment_region_name }}</option>
                  {% else %}
                    <option value="{{ payment_region_code }}">{{ payment_region_name }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-language">{{ entry_language }}</label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_language" id="amazon-login-pay-language" class="form-control">
                {% for language_code, language_name in languages %}
                  {% if language_code == payment_amazon_login_pay_language %}
                    <option value="{{ language_code }}" selected="selected">{{ language_name }}</option>
                  {% else %}
                    <option value="{{ language_code }}">{{ language_name }}</option>
                  {% endif %}
                {% endfor %}
              </select>
              {% if error_curreny %}
                <div class="text-danger">{{ error_curreny }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-merchant-id">{{ entry_merchant_id }}</label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_merchant_id" value="{{ payment_amazon_login_pay_merchant_id }}" placeholder="{{ entry_merchant_id }}" id="amazon-login-pay-merchant-id" class="form-control"/>
              {% if error_merchant_id %}
                <div class="text-danger">{{ error_merchant_id }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-access-key">{{ entry_access_key }}</label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_access_key" value="{{ payment_amazon_login_pay_access_key }}" placeholder="{{ entry_access_key }}" id="amazon-login-pay-access-key" class="form-control"/>
              {% if error_access_key %}
                <div class="text-danger">{{ error_access_key }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-access-secret">{{ entry_access_secret }}</label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_access_secret" value="{{ payment_amazon_login_pay_access_secret }}" placeholder="{{ entry_access_secret }}" id="amazon-login-pay-access-secret" class="form-control"/>
              {% if error_access_secret %}
                <div class="text-danger">{{ error_access_secret }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-client-id">{{ entry_client_id }}</label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_client_id" value="{{ payment_amazon_login_pay_client_id }}" placeholder="{{ entry_client_id }}" id="amazon-login-pay-client-id" class="form-control"/>
              {% if error_client_id %}
                <div class="text-danger">{{ error_client_id }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group required">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-client-secret">{{ entry_client_secret }}</label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_client_secret" value="{{ payment_amazon_login_pay_client_secret }}" placeholder="{{ entry_client_secret }}" id="amazon-login-pay-client-secret" class="form-control"/>
              {% if error_client_secret %}
                <div class="text-danger">{{ error_client_secret }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="input-ipn-token"><span data-toggle="tooltip" title="{{ help_ipn_token }}">{{ entry_ipn_token }}</span></label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_ipn_token" value="{{ payment_amazon_login_pay_ipn_token }}" id="input-ipn-token" class="form-control"/>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="input-ipn-url">{{ entry_ipn_url }}</label>
            <div class="col-sm-10">
              <div class="input-group"><span class="input-group-addon"><i class="fas fa-link"></i></span> <input type="text" readonly value="{{ ipn_url }}" id="input-ipn-url" class="form-control"/>
              </div>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-test">{{ entry_login_pay_test }}</label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_test" id="amazon-login-pay-test" class="form-control">
                {% if payment_amazon_login_pay_test == 'sandbox' %}
                  <option value="sandbox" selected="selected">{{ text_sandbox }}</option>
                {% else %}
                  <option value="sandbox">{{ text_sandbox }}</option>
                {% endif %}
                {% if payment_amazon_login_pay_test == 'live' %}
                  <option value="live" selected="selected">{{ text_live }}</option>
                {% else %}
                  <option value="live">{{ text_live }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-mode"><span data-toggle="tooltip" title="{{ help_pay_mode }}">{{ entry_login_pay_mode }}</span></label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_mode" id="amazon-login-pay-mode" class="form-control">
                {% if payment_amazon_login_pay_mode == 'payment' %}
                  <option value="payment" selected="selected">{{ text_payment }}</option>
                {% else %}
                  <option value="payment">{{ text_payment }}</option>
                {% endif %}
                {% if payment_amazon_login_pay_mode == 'auth' %}
                  <option value="auth" selected="selected">{{ text_auth }}</option>
                {% else %}
                  <option value="auth">{{ text_auth }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-checkout"><span data-toggle="tooltip" title="{{ help_checkout }}">{{ entry_checkout }}</span></label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_checkout" id="amazon-login-checkout-mode" class="form-control">
                {% if payment_amazon_login_pay_checkout == 'account' %}
                  <option value="account" selected="selected">{{ text_account }}</option>
                {% else %}
                  <option value="account">{{ text_account }}</option>
                {% endif %}
                {% if payment_amazon_login_pay_checkout == 'guest' %}
                  <option value="guest" selected="selected">{{ text_guest }}</option>
                {% else %}
                  <option value="guest">{{ text_guest }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-capture-status"><span data-toggle="tooltip" title="{{ help_capture_status }}">{{ entry_capture_status }}</span></label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_capture_status" id="amazon-login-pay-capturet-status" class="form-control">
                <option value="">{{ text_no_capture }}</option>
                {% for order_status in order_statuses %}
                  {% if order_status.order_status_id == payment_amazon_login_pay_capture_status %}
                    <option value="{{ order_status.order_status_id }}" selected="selected">{{ order_status.name }}</option>
                  {% else %}
                    <option value="{{ order_status.order_status_id }}">{{ order_status.name }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-pending-status">{{ entry_pending_status }}</label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_pending_status" id="amazon-login-pay-pendingt-status" class="form-control">
                {% for order_status in order_statuses %}
                  {% if order_status.order_status_id == payment_amazon_login_pay_pending_status %}
                    <option value="{{ order_status.order_status_id }}" selected="selected">{{ order_status.name }}</option>
                  {% else %}
                    <option value="{{ order_status.order_status_id }}">{{ order_status.name }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-minimum-total"><span data-toggle="tooltip" title="{{ help_minimum_total }}">{{ text_minimum_total }}</span></label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_minimum_total" value="{{ payment_amazon_login_pay_minimum_total }}" placeholder="{{ text_minimum_total }}" id="amazon-login-pay-minimum-total" class="form-control"/>
              {% if error_minimum_total %}
                <div class="text-danger">{{ error_minimum_total }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-geo-zone">{{ text_geo_zone }}</label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_geo_zone" id="amazon-login-pay-geo-zone" class="form-control">
                {% if payment_amazon_login_pay_geo_zone == 0 %}
                  <option value="0" selected="selected">{{ text_all_geo_zones }}</option>
                {% else %}
                  <option value="0">{{ text_all_geo_zones }}</option>
                {% endif %}
                {% for geo_zone in geo_zones %}
                  {% if payment_amazon_login_pay_geo_zone == geo_zone.geo_zone_id %}
                    <option value="{{ geo_zone.geo_zone_id }}" selected="selected">{{ geo_zone.name }}</option>
                  {% else %}
                    <option value="{{ geo_zone.geo_zone_id }}">{{ geo_zone.name }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-input-debug"><span data-toggle="tooltip" title="{{ help_debug }}">{{ entry_debug }}</span></label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_debug" id="amazon-login-pay-input-debug" class="form-control">
                {% if payment_amazon_login_pay_debug %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  <option value="0">{{ text_disabled }}</option>
                {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-sort-order">{{ text_sort_order }}</label>
            <div class="col-sm-10">
              <input type="text" name="payment_amazon_login_pay_sort_order" value="{{ payment_amazon_login_pay_sort_order }}" placeholder="{{ text_sort_order }}" id="amazon-login-pay-sort-order" class="form-control"/>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-status">{{ text_status }}</label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_status" id="amazon-login-pay-status" class="form-control">
                {% if payment_amazon_login_pay_status == 1 %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                {% else %}
                  <option value="1">{{ text_enabled }}</option>
                {% endif %}
                {% if payment_amazon_login_pay_status == 0 %}
                  <option value="0" selected="selected">{{ text_disabled }}</option>
                {% else %}
                  <option value="0">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 col-form-label" for="amazon-login-pay-declined_codes"><span data-toggle="tooltip" title="{{ help_declined_codes }}">{{ text_declined_codes }}</span></label>
            <div class="col-sm-10">
              <select name="payment_amazon_login_pay_declined_code" id="amazon-login-pay-declined_code" class="form-control">
                <option value="">{{ text_amazon_no_declined }}</option>
                {% for declined_code in declined_codes %}
                  {% if payment_amazon_login_pay_declined_code == declined_code %}
                    <option value="{{ declined_code }}" selected="selected">{{ declined_code }}</option>
                  {% else %}
                    <option value="{{ declined_code }}">{{ declined_code }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
  <script type="text/javascript">
  $('#button-credentials').on('click', function() {
	  var json = $('#input-credentials').val();
	  try {
		  var credentials = $.parseJSON($('#input-credentials').val());
		  $('#amazon-login-pay-merchant-id').val(credentials['merchant_id']);
		  $('#amazon-login-pay-access-key').val(credentials['access_key']);
		  $('#amazon-login-pay-access-secret').val(credentials['secret_key']);
		  $('#amazon-login-pay-client-id').val(credentials['client_id']);
		  $('#amazon-login-pay-client-secret').val(credentials['client_secret']);
		  $('<input>').attr({
			  type: 'hidden',
			  value: 'true',
			  name: 'language_reload'
		  }).appendTo('#form-amazon-login-pay');
		  $('.float-right > .btn-primary').click();
	  } catch (e) {
		  $('.container-fluid:eq(1)').prepend('<div class="alert alert-danger alert-dismissible"><i class="fas fa-exclamation-circle"></i> {{ error_credentials }}<button type="button" class="close" data-dismiss="alert">&times;</button></div>')
	  }
  });
  //</script>
  <script type="text/javascript">
  $('input[name=\'payment_amazon_login_pay_ipn_token\']').change(function() {
	  var base = '{{ https_catalog }}index.php?route=extension/payment/amazon_login_pay/ipn&token=';
	  var allowedLength = 150 - base.length;
	  var newVal = $(this).val().substr(0, allowedLength);
	  $(this).val(newVal);
	  $('#input-ipn-url').val(base + newVal);
  });
  //</script>
  <script type="text/javascript">
  $('#amazon-login-pay-payment_region').on('change', function() {
	  switch ($(this).val()) {
		  case 'EUR':
			  $('#amazon-login-pay-language').html('<option selected value="de-DE">German</option>');
			  break;
		  case 'GBP':
			  $('#amazon-login-pay-language').html('<option selected value="en-GB">English</option>');
			  break;
		  case 'USD':
			  $('#amazon-login-pay-language').html('<option selected value="en-US">American English</option>');
			  break;
	  }
	  $('<input>').attr({
		  type: 'hidden',
		  value: 'true',
		  name: 'language_reload'
	  }).appendTo('#form-amazon-login-pay');
	  $("#form-amazon-login-pay").submit();
  });
  //</script>
  <script type="text/javascript">
  $('#amazon-login-pay-language').on('change', function() {
	  var language = $(this).val();
	  var mod_lang = language.replace("-", "_");
	  $('input[name=\'language\']').val(mod_lang);
  });
  //</script>
  <script type="text/javascript">
  $('#sign-up').on('click', function() {
	  $("#registration-form").submit();
	  $("#container-credentials").show();
  });
  //</script>
</div>
{{ footer }}
